<template>
	<layout :loading="loading" curPage="servicer" title="运维公司">
		
		<block slot="title">
			<auth url="/admin/servicer/export" class="layui-btn layui-btn-sm">
				<view @tap="downloadExcel">
					批量导出
				</view>
			</auth>
			
			<auth url="/admin/servicer/imports" class="layui-btn layui-btn-sm">
				<view @tap="uploadExcel">
					批量导入
				</view>
			</auth>
			
			<authNav href="/pages/servicer/servicerEdit" url="/admin/servicer/save" class="layui-btn layui-btn-sm">
				<i class="layui-icon layui-icon-add-1"></i>
				添加
			</authNav>
		</block>
		
		<conditions :list="conditonList" :conditions="conditions" @submit="submitSearch"></conditions>

		<div class="layui-form layui-border-box layui-table-view">

			<tableList :list="page.list" :canSelect="false">

				<block slot="head">
					<th>公司信息</th>
					<th class="autoWidth">资质证书</th>
					<th>联系信息</th>
					<th>状态</th>
					<th class="autoWidth">备注</th>
					<th>操作</th>
				</block>

				<block slot="body">

					<tr v-for="( x , index) in page.list" :key="index">
						
						<td>
							<view style="font-weight: bold;color: #000;">
								{{x.name}} 
							</view>
							<view class="fz12 text-muted"  v-if="x.license">
								{{x.license}}
							</view>
							<view class="fz12 text-muted">
								{{x.address}}
							</view>
						</td>
						<td>
							<thumbImg :src="x.licensePic"></thumbImg>
							<thumbImg :src="x.authPic"></thumbImg>
						</td>
						<td>
							{{x.contacts}}
							<view>
								{{x.mobile}}
							</view>
						</td>
						<td :class="{'red':x.status == 2}">
							{{x.statusStr}}
							<view class="fz12 text-muted" v-if="x.status == 2">
								{{x.createTime}}
							</view>
						</td>
						<td>
							{{x.remark}}
							{{x.refuseReason ? '审核拒绝原因：' + x.refuseReason : ''}}
						</td>
						<td>
							<authNav :href="'/pages/company/companyList?tsc.serviserId=' + x.id" url="/admin/company/list" class="layui-btn layui-btn-xs">
								运维企业
							</authNav>
							<authNav :href="'/pages/servicer/servicerEdit?id=' + x.id" url="/admin/servicer/save" class="layui-btn layui-btn-xs">
								编辑
							</authNav>
							<authBtn :url="'/admin/servicer/delete?id='+x.id" confirm="delete" class="layui-btn layui-btn-xs">
								删除
							</authBtn>
							<authBtn v-if="x.status == 2" :url="'/admin/servicer/audit?isPass=1&id='+x.id" confirm="确认审核通过吗？" class="layui-btn layui-btn-xs">
								审核通过
							</authBtn>
							<auth v-if="x.status == 2" class="layui-btn layui-btn-xs" url="/admin/servicer/audit">
								<view @tap="toShowDrawForm(x)" >
									审核拒绝
								</view>
							</auth>
						</td>
					</tr>

				</block>

			</tableList>
			
			<emptyTips :loading="loading" :list="page.list"></emptyTips>

			<paginate :page="page" @switchPage="switchPage" @changePageSize="changePageSize"></paginate>
			
			<alertForm action="/admin/servicer/audit?isPass=0" :show="showDrawForm" @cancel="showDrawForm = false" @success="drawSuccess"
			 :width="500" title="审核拒绝">
				  
				 <inputGroup title="公司名称" name="id" :value="drawData.name" :hiddenValue="drawData.id"></inputGroup> 
				  
				 <textareaGroup type="text" title="拒绝原因" name="reason|拒绝原因"></textareaGroup>
				
			</alertForm>
			
		</div>


	</layout>
</template>

<script>
	export default {
		data() {
			return {
				conditonList:[
					{title:"公司名称",name:"ts.name",type:"varchar"},
					{title:"手机号码",name:"ts.mobile",type:"mobile"},
					{title:"状态",name:"ts.status",type:"options",list:[]}
				],
				conditions: {},
				loading: true ,
				action: "/admin/servicer/list",
				page: {
					pageNumber: 1,
					lastPage: true,
					totalPage: 1,
					list: [],
					totalRow: 0,
					pageSize: 10
				},
				showDrawForm : false ,
				drawData:{
					show : false 
				},
			}
		},
		
		onLoad:function(res){
			this.conditions = res || {} ;
		},

		onShow() {
			var that = this ;
			this.kit.getPage(this.action,function(res){
				that.conditonList[2].list = res.servicerStatusList ;
			});
		},

		methods: {
			
			drawSuccess:function(e){
				this.showDrawForm = false ;
				this.switchPage();
			},
			
			toShowDrawForm:function(drawData){
				this.showDrawForm = true ;
				this.drawData = drawData ;
			},
			
			submitSearch:function(conditions){
				this.conditions = conditions ;
				this.switchPage(1);
			},
			
			switchPage: function(pageNumber) {
				this.page.pageNumber = pageNumber || this.page.pageNumber ;
				this.kit.getPage(this.action);
			},
			
			changePageSize: function(pageSize) {
				this.page.pageSize = pageSize;
				this.page.pageNumber = 1;
				this.kit.getPage(this.action);
			},
			
			uploadExcel:function(res){
				uni.showModal({
					title:'提示',
					content:'使用批量导入功能时，如系统已录入该企业则会根据excel更新企业数据。请按照导入模板格式制作您的excel文件，仅支持.xls格式的excel文件。',
					showCancel:true,
					confirmColor:'#5d83f7' ,
					confirmText:"开始导入" ,
					cancelText: "下载模板" ,
					success : (e)=>{
						if(e.confirm){
							uni.chooseFile({
								fileType : "application/vnd.ms-excel" ,
								success :(res) =>{
									var path = res.path ;
									this.upload(path);
								}
							});
						}else{
							this.kit.download("/admin/company/getUploadTpl?tplName=importServicer.xls&reName=运维企业信息导入模板.xls");
						}
					}
				});
			},
			
			upload : function(path){
				this.kit.uploadFile("/admin/servicer/imports" , path ,(e)=>{
					this.page.pageNumber = 1 ;
					this.kit.getPage(this.action);
					uni.showModal({
						title:'提示',
						content:`本次共导入${e.saveCount}条数据，更新${e.updateCount}条数据，未导入${e.skipCount}条数据。`,
						showCancel:false,
						confirmColor:'#3385ff',
						success : (e)=>{
							
						}
					});
				});
			},
			
			downloadExcel:function(res){
				var data = this.conditions;
				uni.showLoading({
					title:"请稍后...",
					mask: true 
				});
				this.kit.get("/admin/servicer/export",data, (res) => {
					uni.hideLoading();
					this.kit.download("/admin/company/downloadExcel?fileName=" + res.fileName );
				});
			}
		}
	}
</script>